import SwiftUI

struct AnimatableProperties_Anchor : View {
    @State var isOpen: Bool = false
    
    var body: some View {
        VStack(spacing: 30) {
            Text("Animatable Properties")
                .font(.largeTitle)
            
            Text("Anchor")
                .font(.title)
            
            Text(".....")
            
            makeDemoView()
            
            Spacer()
            
            Button(action: {
                isOpen.toggle()
            }, label: {
                Text("Rotate")
                    .font(.title)
                    .padding(.bottom, 50)
            })
        }
    }
    
    func makeDemoView() -> some View {
        VStack {
            // 2 Rectangles
            ZStack {
                RoundedRectangle(cornerRadius: 12)
                    .frame(width: 300, height: 150)
                    .foregroundColor(.pink)
                
                Text("Rotate around top leading")
            }
            .rotationEffect(Angle(degrees: isOpen ? 220.0 : 0), anchor: .topLeading)
            .animation(.easeInOut, value: isOpen)
            
            
            ZStack {
                RoundedRectangle(cornerRadius: 12)
                    .frame(width: 300, height: 150)
                    .foregroundColor(.blue)


                Text("Rotate around bottom trailing")                
            }
            .rotationEffect(Angle(degrees: isOpen ? 220.0 : 0), anchor: .bottomTrailing)
            .animation(.easeInOut, value: isOpen)
        }
    }
}
